package com.example.chuqq.gpssigninapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
//
//    LocationListener locationListener = new LocationListener() {
//
//        @Override
//        public void onStatusChanged(String provider, int status, Bundle arg2) {
//
//        }
//
//        @Override
//        public void onProviderEnabled(String provider) {
//
//        }
//
//        @Override
//        public void onProviderDisabled(String provider) {
//
//        }
//
//        @Override
//        public void onLocationChanged(Location location) {
//            Log.i("GPSApp", "onLocationChanged()====");
//            try {
//                double lat = location.getLatitude();
//                double lon = location.getLongitude();
//                Log.i("GPSApp", "lat:" + lat + ", lon:" + lon);
//
//                // 发送http请求
//                OkHttpClient client = new OkHttpClient();
//                Request request = new Request.Builder()
//                        .url("http://mp.xxying.com:8091/gpssignin/gps?lat=" + lat + "&lon=" + lon)
////                        .url("http://192.168.1.106:8091/gpssignin/gps?lat=" + lat + "&lon=" + lon)
//                        .build();
//
//                Call call = client.newCall(request);
//                call.enqueue(new Callback() {
//                    @Override
//                    public void onFailure(Call call, IOException e) {
//                        e.printStackTrace();
//                    }
//
//                    @Override
//                    public void onResponse(Call call, Response response) throws IOException {
//                        String result = response.body().string();
//                        Log.i("GPSApp", "res: " + result);
//                    }
//                });
//            } catch (SecurityException e) {
//                e.printStackTrace();
//            }
//        }
//    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//
//        Log.i("GPSApp", "onCreate()====");
//        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//
//        try {
//            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 0, locationListener);
//            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 2000, 0, locationListener);
//            locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 2000, 0, locationListener);
//        } catch (SecurityException e) {
//            e.printStackTrace();
//        }
    }
}
